#!/bin/bash
datafile=/var/lib/mongodb
logfile=/var/log/mongodb
days=1
echo "execute here" >> /opt/log
logsize=`du -m /var/log/mongodb/mongod.log|awk '{print $1}'`
echo "logsize="$logsize
if ! grep "cut_mongodb_log" /etc/crontab >>/dev/null; then
                echo "设置mongo日志清理脚本到定时任务"
                echo "0 0 * * *  root /bin/sh /opt/cut_mongodb_log.sh" >> /etc/crontab
                service crond restart 2>/dev/null
fi
if [ $logsize -gt 100 ];then
        echo "开始切分日志"
        /bin/kill -SIGUSR1 `cat $datafile/mongod.lock`
        find $logfile/ -mtime +$days -delete
fi